﻿using Microsoft.International.Converters.PinYinConverter;

using System.Text;

namespace OpenPms.Controllers;

[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(IgnoreApi =true)]
public class PinYinController : ControllerBase
{
    [HttpGet("{id}")]
    public string Get(string id)
    {
        if (string.IsNullOrEmpty(id))
            return "";
        StringBuilder sb = new StringBuilder();
        foreach (var c in id)
        {
            if (ChineseChar.IsValidChar(c))
            {
                var chChar = new ChineseChar(c);
                sb.Append(chChar.Pinyins[0][0]);
            }
            else
                sb.Append(c);
        }
        return sb.ToString();
    }
}
